package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfOrderDAO;
import com.AAL.Model.StatusOfOrder;
import com.AAL.Utils.HibernateUtil;

public class StatusOfOrderDAO implements IStatusOfOrderDAO {

	@Override
	public StatusOfOrder getStatusOfOrder(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfOrder statusOfOrder = (StatusOfOrder) session.load(
				StatusOfOrder.class, statusID);
		return statusOfOrder;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfOrder> getAllStatusOfOrders() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfOrder> lstStatusOfOrders = null;
		try {
			lstStatusOfOrders = (List<StatusOfOrder>) session.createQuery(
					"from StatusOfOrder").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfOrders;
	}

}
